package com.codermn.String类型测试;

import java.lang.reflect.Field;

/**
 * <p>
 *     不同对象中的String值相等时，其指向的是同一个String constant pool中的地址
 * </p>
 * @author jxau_scf
 * @date 2021/9/2 - 14:46
 */
public class Demo1 {
    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
        String str1 = "abc";
        String str2 = new String("abc");
        Field declaredField = String.class.getDeclaredField("value");
        declaredField.setAccessible(true);
        char[] values = (char[]) declaredField.get(str1);
        values[2] = 'h';
        System.out.println("str1: "+str1);
        System.out.println("str2: "+str2);

    }
}
